8 * Need the CacheManager to be loaded
10 require_once( 'CacheManager.php' );
11 require_once( 'Revision.php' );
13 $wgArticleCurContentFields = false;
14 $wgArticleOldContentFields = false;
17 * Class representing a MediaWiki article and history.
19 * See design.txt for an overview.
20 * Note: edit user interface and cache support functions have been
21 * moved to separate EditPage and CacheManager classes.
29 var $mContent, $mContentLoaded;
30 var $mUser, $mTimestamp, $mUserText;
31 var $mCounter, $mComment, $mGoodAdjustment, $mTotalAdjustment;
32 var $mMinorEdit, $mRedirectedFrom;
33 var $mTouched, $mFileCache, $mTitle;
42 * Constructor and clear the article
43 * @param mixed &$title
45 function Article( &$title ) {
46 $this->mTitle
=& $title;
51 * get the title object of the article
63 $this->mDataLoaded
= false;
64 $this->mContentLoaded
= false;
66 $this->mCurID
= $this->mUser
= $this->mCounter
= -1; # Not loaded
67 $this->mRedirectedFrom
= $this->mUserText
=
68 $this->mTimestamp
= $this->mComment
= $this->mFileCache
= '';
69 $this->mGoodAdjustment
= $this->mTotalAdjustment
= 0;
70 $this->mTouched
= '19700101000000';
71 $this->mForUpdate
= false;
72 $this->mIsRedirect
= false;
73 $this->mRevIdFetched
= 0;
77 * Note that getContent/loadContent may follow redirects if
78 * not told otherwise, and so may cause a change to mTitle.
81 * @return Return the text of this revision
83 function getContent( $noredir ) {
84 global $wgRequest, $wgUser, $wgOut;
86 # Get variables from query string :P
87 $action = $wgRequest->getText( 'action', 'view' );
88 $section = $wgRequest->getText( 'section' );
89 $preload = $wgRequest->getText( 'preload' );
91 $fname = 'Article::getContent';
92 wfProfileIn( $fname );
94 if ( 0 == $this->getID() ) {
95 if ( 'edit' == $action ) {
96 wfProfileOut( $fname );
98 # If requested, preload some text.
99 $text=$this->getPreloadedText($preload);
101 # We used to put MediaWiki:Newarticletext here if
102 # $text was empty at this point.
103 # This is now shown above the edit box instead.
106 wfProfileOut( $fname );
107 $wgOut->setRobotpolicy( 'noindex,nofollow' );
109 $ret = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
110 return "<div class='noarticletext'>$ret</div>";
112 $this->loadContent( $noredir );
113 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
114 if ( $this->mTitle
->getNamespace() == NS_USER_TALK
&&
115 $wgUser->isIP($this->mTitle
->getText()) &&
118 wfProfileOut( $fname );
119 return $this->mContent
. "\n" .wfMsg('anontalkpagetext');
121 if($action=='edit') {
123 if($section=='new') {
124 wfProfileOut( $fname );
125 $text=$this->getPreloadedText($preload);
129 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
130 # comments to be stripped as well)
131 $rv=$this->getSection($this->mContent
,$section);
132 wfProfileOut( $fname );
136 wfProfileOut( $fname );
137 return $this->mContent
;
143 This function accepts a title string as parameter
144 ($preload). If this string is non-empty, it attempts
145 to fetch the current revision text.
147 function getPreloadedText($preload) {
149 $preloadTitle=Title
::newFromText($preload);
150 if(isset($preloadTitle) && $preloadTitle->userCanRead()) {
151 $rev=Revision
::newFromTitle($preloadTitle);
153 return $rev->getText();
161 * This function returns the text of a section, specified by a number ($section).
162 * A section is text under a heading like == Heading == or <h1>Heading</h1>, or
163 * the first section before any such heading (section 0).
165 * If a section contains subsections, these are also returned.
167 * @param string $text text to look in
168 * @param integer $section section number
169 * @return string text of the requested section
171 function getSection($text,$section) {
173 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
174 # comments to be stripped as well)
176 $parser=new Parser();
177 $parser->mOutputType
=OT_WIKI
;
178 $parser->mOptions
= new ParserOptions();
179 $striptext=$parser->strip($text, $striparray, true);
181 # now that we can be sure that no pseudo-sections are in the source,
182 # split it up by section
185 '/(^=+.+?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)(?!\S)/mi',
187 PREG_SPLIT_DELIM_CAPTURE
);
191 $headline=$secs[$section*2-1];
192 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$headline,$matches);
195 # translate wiki heading into level
196 if(strpos($hlevel,'=')!==false) {
197 $hlevel=strlen($hlevel);
200 $rv=$headline. $secs[$section*2];
204 while(!empty($secs[$count*2-1]) && !$break) {
206 $subheadline=$secs[$count*2-1];
207 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$subheadline,$matches);
208 $subhlevel=$matches[1];
209 if(strpos($subhlevel,'=')!==false) {
210 $subhlevel=strlen($subhlevel);
212 if($subhlevel > $hlevel) {
213 $rv.=$subheadline.$secs[$count*2];
215 if($subhlevel <= $hlevel) {
222 # reinsert stripped tags
223 $rv=$parser->unstrip($rv,$striparray);
224 $rv=$parser->unstripNoWiki($rv,$striparray);
231 * Return an array of the columns of the "cur"-table
233 function getContentFields() {
234 return $wgArticleContentFields = array(
235 'old_text','old_flags',
236 'rev_timestamp','rev_user', 'rev_user_text', 'rev_comment','page_counter',
237 'page_namespace', 'page_title', 'page_restrictions','page_touched','page_is_redirect' );
241 * Return the oldid of the article that is to be shown.
242 * For requests with a "direction", this is not the oldid of the
245 function getOldID() {
246 global $wgRequest, $wgOut;
249 if ( isset( $lastid ) ) {
253 $oldid = $wgRequest->getVal( 'oldid' );
254 if ( isset( $oldid ) ) {
255 $oldid = intval( $oldid );
256 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
257 $nextid = $this->mTitle
->getNextRevisionID( $oldid );
261 $wgOut->redirect( $this->mTitle
->getFullURL( 'redirect=no' ) );
263 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
264 $previd = $this->mTitle
->getPreviousRevisionID( $oldid );
273 return @$oldid; # "@" to be able to return "unset" without PHP complaining
278 * Load the revision (including cur_text) into this object
280 function loadContent( $noredir = false ) {
281 global $wgOut, $wgRequest;
283 if ( $this->mContentLoaded
) return;
286 $oldid = $this->getOldID();
287 $redirect = $wgRequest->getVal( 'redirect' );
289 $fname = 'Article::loadContent';
291 # Pre-fill content with error message so that if something
292 # fails we'll have something telling us what we intended.
294 $t = $this->mTitle
->getPrefixedText();
296 $noredir = $noredir ||
($wgRequest->getVal( 'redirect' ) == 'no')
297 ||
$wgRequest->getCheck( 'rdfrom' );
298 $this->mOldId
= $oldid;
299 $this->fetchContent( $oldid, $noredir, true );
304 * Fetch a page record with the given conditions
305 * @param Database $dbr
306 * @param array $conditions
309 function pageData( &$dbr, $conditions ) {
310 return $dbr->selectRow( 'page',
324 'Article::pageData' );
327 function pageDataFromTitle( &$dbr, $title ) {
328 return $this->pageData( $dbr, array(
329 'page_namespace' => $title->getNamespace(),
330 'page_title' => $title->getDBkey() ) );
333 function pageDataFromId( &$dbr, $id ) {
334 return $this->pageData( $dbr, array(
335 'page_id' => intval( $id ) ) );
339 * Set the general counter, title etc data loaded from
342 * @param object $data
345 function loadPageData( $data ) {
346 $this->mTitle
->loadRestrictions( $data->page_restrictions
);
347 $this->mTitle
->mRestrictionsLoaded
= true;
349 $this->mCounter
= $data->page_counter
;
350 $this->mTouched
= wfTimestamp( TS_MW
, $data->page_touched
);
351 $this->mIsRedirect
= $data->page_is_redirect
;
352 $this->mLatest
= $data->page_latest
;
354 $this->mDataLoaded
= true;
358 * Get text of an article from database
359 * @param int $oldid 0 for whatever the latest revision is
360 * @param bool $noredir Set to false to follow redirects
361 * @param bool $globalTitle Set to true to change the global $wgTitle object when following redirects or other unexpected title changes
364 function fetchContent( $oldid = 0, $noredir = true, $globalTitle = false ) {
365 if ( $this->mContentLoaded
) {
366 return $this->mContent
;
368 $dbr =& $this->getDB();
369 $fname = 'Article::fetchContent';
371 # Pre-fill content with error message so that if something
372 # fails we'll have something telling us what we intended.
373 $t = $this->mTitle
->getPrefixedText();
375 $t .= ',oldid='.$oldid;
377 if( isset( $redirect ) ) {
378 $redirect = ($redirect == 'no') ?
'no' : 'yes';
379 $t .= ',redirect='.$redirect;
381 $this->mContent
= wfMsg( 'missingarticle', $t );
384 $revision = Revision
::newFromId( $oldid );
385 if( is_null( $revision ) ) {
386 wfDebug( "$fname failed to retrieve specified revision, id $oldid\n" );
389 $data = $this->pageDataFromId( $dbr, $revision->getPage() );
391 wfDebug( "$fname failed to get page data linked to revision id $oldid\n" );
394 $this->mTitle
= Title
::makeTitle( $data->page_namespace
, $data->page_title
);
395 $this->loadPageData( $data );
397 if( !$this->mDataLoaded
) {
398 $data = $this->pageDataFromTitle( $dbr, $this->mTitle
);
400 wfDebug( "$fname failed to find page data for title " . $this->mTitle
->getPrefixedText() . "\n" );
403 $this->loadPageData( $data );
405 $revision = Revision
::newFromId( $this->mLatest
);
406 if( is_null( $revision ) ) {
407 wfDebug( "$fname failed to retrieve current page, rev_id $data->page_latest\n" );
412 # If we got a redirect, follow it (unless we've been told
413 # not to by either the function parameter or the query
414 if ( !$oldid && !$noredir ) {
415 $rt = Title
::newFromRedirect( $revision->getText() );
416 # process if title object is valid and not special:userlogout
417 if ( $rt && ! ( $rt->getNamespace() == NS_SPECIAL
&& $rt->getText() == 'Userlogout' ) ) {
418 # Gotta hand redirects to special pages differently:
419 # Fill the HTTP response "Location" header and ignore
420 # the rest of the page we're on.
421 global $wgDisableHardRedirects;
422 if( $globalTitle && !$wgDisableHardRedirects ) {
424 if ( $rt->getInterwiki() != '' && $rt->isLocal() ) {
425 $source = $this->mTitle
->getFullURL( 'redirect=no' );
426 $wgOut->redirect( $rt->getFullURL( 'rdfrom=' . urlencode( $source ) ) ) ;
429 if ( $rt->getNamespace() == NS_SPECIAL
) {
430 $wgOut->redirect( $rt->getFullURL() );
434 $redirData = $this->pageDataFromTitle( $dbr, $rt );
436 $redirRev = Revision
::newFromId( $redirData->page_latest
);
437 if( !is_null( $redirRev ) ) {
438 $this->mRedirectedFrom
= $this->mTitle
->getPrefixedText();
441 $this->loadPageData( $data );
442 $revision = $redirRev;
448 # if the title's different from expected, update...
451 if( !$this->mTitle
->equals( $wgTitle ) ) {
452 $wgTitle = $this->mTitle
;
456 # Back to the business at hand...
457 $this->mContent
= $revision->getText();
459 $this->mUser
= $revision->getUser();
460 $this->mUserText
= $revision->getUserText();
461 $this->mComment
= $revision->getComment();
462 $this->mTimestamp
= wfTimestamp( TS_MW
, $revision->getTimestamp() );
464 $this->mRevIdFetched
= $revision->getID();
465 $this->mContentLoaded
= true;
466 $this->mRevision
=& $revision;
468 return $this->mContent
;
472 * Gets the article text without using so many damn globals
473 * Returns false on error
475 * @param integer $oldid
477 function getContentWithoutUsingSoManyDamnGlobals( $oldid = 0, $noredir = false ) {
478 return $this->fetchContent( $oldid, $noredir, false );
482 * Read/write accessor to select FOR UPDATE
484 function forUpdate( $x = NULL ) {
485 return wfSetVar( $this->mForUpdate
, $x );
489 * Get the database which should be used for reads
492 $ret =& wfGetDB( DB_MASTER
);
494 #if ( $this->mForUpdate ) {
495 $ret =& wfGetDB( DB_MASTER
);
497 # $ret =& wfGetDB( DB_SLAVE );
503 * Get options for all SELECT statements
504 * Can pass an option array, to which the class-wide options will be appended
506 function getSelectOptions( $options = '' ) {
507 if ( $this->mForUpdate
) {
508 if ( is_array( $options ) ) {
509 $options[] = 'FOR UPDATE';
511 $options = 'FOR UPDATE';
518 * Return the Article ID
521 if( $this->mTitle
) {
522 return $this->mTitle
->getArticleID();
529 * Returns true if this article exists in the database.
533 return $this->getId() != 0;
537 * Get the view count for this article
539 function getCount() {
540 if ( -1 == $this->mCounter
) {
541 $id = $this->getID();
542 $dbr =& $this->getDB();
543 $this->mCounter
= $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
544 'Article::getCount', $this->getSelectOptions() );
546 return $this->mCounter
;
550 * Would the given text make this article a "good" article (i.e.,
551 * suitable for including in the article count)?
552 * @param string $text Text to analyze
553 * @return integer 1 if it can be counted else 0
555 function isCountable( $text ) {
556 global $wgUseCommaCount;
558 if ( NS_MAIN
!= $this->mTitle
->getNamespace() ) { return 0; }
559 if ( $this->isRedirect( $text ) ) { return 0; }
560 $token = ($wgUseCommaCount ?
',' : '[[' );
561 if ( false === strstr( $text, $token ) ) { return 0; }
566 * Tests if the article text represents a redirect
568 function isRedirect( $text = false ) {
569 if ( $text === false ) {
570 $this->loadContent();
571 $titleObj = Title
::newFromRedirect( $this->fetchContent() );
573 $titleObj = Title
::newFromRedirect( $text );
575 return $titleObj !== NULL;
579 * Returns true if the currently-referenced revision is the current edit
580 * to this page (and it exists).
583 function isCurrent() {
584 return $this->exists() &&
585 isset( $this->mRevision
) &&
586 $this->mRevision
->isCurrent();
590 * Loads everything except the text
591 * This isn't necessary for all uses, so it's only done if needed.
594 function loadLastEdit() {
597 if ( -1 != $this->mUser
)
600 # New or non-existent articles have no user information
601 $id = $this->getID();
602 if ( 0 == $id ) return;
604 $this->mLastRevision
= Revision
::loadFromPageId( $this->getDB(), $id );
605 if( !is_null( $this->mLastRevision
) ) {
606 $this->mUser
= $this->mLastRevision
->getUser();
607 $this->mUserText
= $this->mLastRevision
->getUserText();
608 $this->mTimestamp
= $this->mLastRevision
->getTimestamp();
609 $this->mComment
= $this->mLastRevision
->getComment();
610 $this->mMinorEdit
= $this->mLastRevision
->isMinor();
614 function getTimestamp() {
615 $this->loadLastEdit();
616 return wfTimestamp(TS_MW
, $this->mTimestamp
);
620 $this->loadLastEdit();
624 function getUserText() {
625 $this->loadLastEdit();
626 return $this->mUserText
;
629 function getComment() {
630 $this->loadLastEdit();
631 return $this->mComment
;
634 function getMinorEdit() {
635 $this->loadLastEdit();
636 return $this->mMinorEdit
;
639 function getRevIdFetched() {
640 $this->loadLastEdit();
641 return $this->mRevIdFetched
;
644 function getContributors($limit = 0, $offset = 0) {
645 $fname = 'Article::getContributors';
647 # XXX: this is expensive; cache this info somewhere.
649 $title = $this->mTitle
;
651 $dbr =& $this->getDB();
652 $revTable = $dbr->tableName( 'revision' );
653 $userTable = $dbr->tableName( 'user' );
654 $encDBkey = $dbr->addQuotes( $title->getDBkey() );
655 $ns = $title->getNamespace();
656 $user = $this->getUser();
657 $pageId = $this->getId();
659 $sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp
660 FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
661 WHERE rev_page = $pageId
662 AND rev_user != $user
663 GROUP BY rev_user, rev_user_text, user_real_name
664 ORDER BY timestamp DESC";
666 if ($limit > 0) { $sql .= ' LIMIT '.$limit; }
667 $sql .= ' '. $this->getSelectOptions();
669 $res = $dbr->query($sql, $fname);
671 while ( $line = $dbr->fetchObject( $res ) ) {
672 $contribs[] = array($line->rev_user
, $line->rev_user_text
, $line->user_real_name
);
675 $dbr->freeResult($res);
680 * This is the default action of the script: just view the page of
684 global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgLang;
685 global $wgLinkCache, $IP, $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol;
686 global $wgEnotif, $wgParser, $wgParserCache, $wgUseTrackbacks;
687 $sk = $wgUser->getSkin();
689 $fname = 'Article::view';
690 wfProfileIn( $fname );
691 # Get variables from query string
692 $oldid = $this->getOldID();
693 $diff = $wgRequest->getVal( 'diff' );
694 $rcid = $wgRequest->getVal( 'rcid' );
695 $rdfrom = $wgRequest->getVal( 'rdfrom' );
697 $wgOut->setArticleFlag( true );
698 $wgOut->setRobotpolicy( 'index,follow' );
699 # If we got diff and oldid in the query, we want to see a
700 # diff page instead of the article.
702 if ( !is_null( $diff ) ) {
703 require_once( 'DifferenceEngine.php' );
704 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
706 $de = new DifferenceEngine( $oldid, $diff, $rcid );
707 // DifferenceEngine directly fetched the revision:
708 $this->mRevIdFetched
= $de->mNewid
;
712 # Run view updates for current revision only
713 $this->viewUpdates();
715 wfProfileOut( $fname );
719 if ( empty( $oldid ) && $this->checkTouched() ) {
720 $wgOut->setETag($wgParserCache->getETag($this, $wgUser));
722 if( $wgOut->checkLastModified( $this->mTouched
) ){
723 wfProfileOut( $fname );
725 } else if ( $this->tryFileCache() ) {
726 # tell wgOut that output is taken care of
728 $this->viewUpdates();
729 wfProfileOut( $fname );
733 # Should the parser cache be used?
734 $pcache = $wgEnableParserCache &&
735 intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
738 wfDebug( 'Article::view using parser cache: ' . ($pcache ?
'yes' : 'no' ) . "\n" );
742 if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
746 if ( !$outputDone ) {
747 $text = $this->getContent( false ); # May change mTitle by following a redirect
749 # Another whitelist check in case oldid or redirects are altering the title
750 if ( !$this->mTitle
->userCanRead() ) {
751 $wgOut->loginToUse();
756 # We're looking at an old revision
758 if ( !empty( $oldid ) ) {
759 $this->setOldSubtitle( isset($this->mOldId
) ?
$this->mOldId
: $oldid );
760 $wgOut->setRobotpolicy( 'noindex,follow' );
762 if ( '' != $this->mRedirectedFrom
) {
763 $sk = $wgUser->getSkin();
764 $redir = $sk->makeKnownLink( $this->mRedirectedFrom
, '',
766 $s = wfMsg( 'redirectedfrom', $redir );
767 $wgOut->setSubtitle( $s );
769 # Can't cache redirects
771 } elseif ( !empty( $rdfrom ) ) {
772 global $wgRedirectSources;
773 if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
774 $sk = $wgUser->getSkin();
775 $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
776 $s = wfMsg( 'redirectedfrom', $redir );
777 $wgOut->setSubtitle( $s );
781 # wrap user css and user js in pre and don't parse
782 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
784 $this->mTitle
->getNamespace() == NS_USER
&&
785 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle
->getDBkey())
787 $wgOut->addWikiText( wfMsg('clearyourcache'));
788 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent
)."\n</pre>" );
789 } else if ( $rt = Title
::newFromRedirect( $text ) ) {
791 $imageUrl = $wgStylePath.'/common/images/redirect.png';
792 $targetUrl = $rt->escapeLocalURL();
793 $titleText = htmlspecialchars( $rt->getPrefixedText() );
794 $link = $sk->makeLinkObj( $rt );
796 $wgOut->addHTML( '<img valign="center" src="'.$imageUrl.'" alt="#REDIRECT" />' .
797 '<span class="redirectText">'.$link.'</span>' );
799 $parseout = $wgParser->parse($text, $this->mTitle
, ParserOptions
::newFromUser($wgUser));
800 $catlinks = $parseout->getCategoryLinks();
801 $wgOut->addCategoryLinks($catlinks);
802 $skin = $wgUser->getSkin();
803 } else if ( $pcache ) {
804 # Display content and save to parser cache
805 $wgOut->addPrimaryWikiText( $text, $this );
807 # Display content, don't attempt to save to parser cache
809 # Don't show section-edit links on old revisions... this way lies madness.
810 if( !$this->isCurrent() ) {
811 $oldEditSectionSetting = $wgOut->mParserOptions
->setEditSection( false );
813 $wgOut->addWikiText( $text );
815 if( !$this->isCurrent() ) {
816 $wgOut->mParserOptions
->setEditSection( $oldEditSectionSetting );
820 /* title may have been set from the cache */
821 $t = $wgOut->getPageTitle();
823 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
826 # If we have been passed an &rcid= parameter, we want to give the user a
827 # chance to mark this new article as patrolled.
831 && $wgUser->isLoggedIn()
832 && ( $wgUser->isAllowed('patrol') ||
!$wgOnlySysopsCanPatrol ) )
835 "<div class='patrollink'>" .
836 wfMsg ( 'markaspatrolledlink',
837 $sk->makeKnownLinkObj( $this->mTitle
, wfMsg('markaspatrolledtext'), "action=markpatrolled&rcid=$rcid" )
844 if ($wgUseTrackbacks)
845 $this->addTrackbacks();
847 # Put link titles into the link cache
848 $wgOut->transformBuffer();
850 # Add link titles as META keywords
851 $wgOut->addMetaTags() ;
853 $this->viewUpdates();
854 wfProfileOut( $fname );
857 function addTrackbacks() {
858 global $wgOut, $wgUser;
860 $dbr =& wfGetDB(DB_SLAVE
);
862 /* FROM */ 'trackbacks',
863 /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
864 /* WHERE */ array('tb_page' => $this->getID())
867 if (!$dbr->numrows($tbs))
871 while ($o = $dbr->fetchObject($tbs)) {
873 if ($wgUser->isSysop()) {
874 $delurl = $this->mTitle
->getFullURL("action=deletetrackback&tbid="
875 . $o->tb_id
. "&token=" . $wgUser->editToken());
876 $rmvtxt = wfMsg('trackbackremove', $delurl);
878 $tbtext .= wfMsg(strlen($o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
885 $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
888 function deletetrackback() {
889 global $wgUser, $wgRequest, $wgOut, $wgTitle;
891 if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
892 $wgOut->addWikitext(wfMsg('sessionfailure'));
896 if ((!$wgUser->isAllowed('delete'))) {
897 $wgOut->sysopRequired();
902 $wgOut->readOnlyPage();
906 $db =& wfGetDB(DB_MASTER
);
907 $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
908 $wgTitle->invalidateCache();
909 $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
915 $wgOut->setArticleBodyOnly(true);
920 * Insert a new empty page record for this article.
921 * This *must* be followed up by creating a revision
922 * and running $this->updateToLatest( $rev_id );
923 * or else the record will be left in a funky state.
924 * Best if all done inside a transaction.
926 * @param Database $dbw
927 * @param string $restrictions
928 * @return int The newly created page_id key
931 function insertOn( &$dbw, $restrictions = '' ) {
932 $fname = 'Article::insertOn';
933 wfProfileIn( $fname );
935 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
936 $dbw->insert( 'page', array(
937 'page_id' => $page_id,
938 'page_namespace' => $this->mTitle
->getNamespace(),
939 'page_title' => $this->mTitle
->getDBkey(),
941 'page_restrictions' => $restrictions,
942 'page_is_redirect' => 0, # Will set this shortly...
944 'page_random' => wfRandom(),
945 'page_touched' => $dbw->timestamp(),
946 'page_latest' => 0, # Fill this in shortly...
948 $newid = $dbw->insertId();
950 $this->mTitle
->resetArticleId( $newid );
952 wfProfileOut( $fname );
957 * Update the page record to point to a newly saved revision.
959 * @param Database $dbw
960 * @param Revision $revision -- for ID number, and text used to set
961 length and redirect status fields
962 * @param int $lastRevision -- if given, will not overwrite the page field
963 * when different from the currently set value.
964 * Giving 0 indicates the new page flag should
966 * @return bool true on success, false on failure
969 function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
970 $fname = 'Article::updateToRevision';
971 wfProfileIn( $fname );
973 $conditions = array( 'page_id' => $this->getId() );
974 if( !is_null( $lastRevision ) ) {
975 # An extra check against threads stepping on each other
976 $conditions['page_latest'] = $lastRevision;
979 $text = $revision->getText();
980 $dbw->update( 'page',
982 'page_latest' => $revision->getId(),
983 'page_touched' => $dbw->timestamp(),
984 'page_is_new' => ($lastRevision === 0) ?
1 : 0,
985 'page_is_redirect' => Article
::isRedirect( $text ) ?
1 : 0,
986 'page_len' => strlen( $text ),
991 wfProfileOut( $fname );
992 return ( $dbw->affectedRows() != 0 );
996 * If the given revision is newer than the currently set page_latest,
997 * update the page record. Otherwise, do nothing.
999 * @param Database $dbw
1000 * @param Revision $revision
1002 function updateIfNewerOn( &$dbw, $revision ) {
1003 $fname = 'Article::updateIfNewerOn';
1004 wfProfileIn( $fname );
1006 $row = $dbw->selectRow(
1007 array( 'revision', 'page' ),
1008 array( 'rev_id', 'rev_timestamp' ),
1010 'page_id' => $this->getId(),
1011 'page_latest=rev_id' ),
1014 if( wfTimestamp(TS_MW
, $row->rev_timestamp
) >= $revision->getTimestamp() ) {
1015 wfProfileOut( $fname );
1018 $prev = $row->rev_id
;
1020 # No or missing previous revision; mark the page as new
1024 $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
1025 wfProfileOut( $fname );
1030 * Theoretically we could defer these whole insert and update
1031 * functions for after display, but that's taking a big leap
1032 * of faith, and we want to be able to report database
1033 * errors at some point.
1036 function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
1037 global $wgOut, $wgUser;
1038 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
1040 $fname = 'Article::insertNewArticle';
1041 wfProfileIn( $fname );
1043 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1044 &$summary, &$isminor, &$watchthis, NULL ) ) ) {
1045 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1046 wfProfileOut( $fname );
1050 $this->mGoodAdjustment
= $this->isCountable( $text );
1051 $this->mTotalAdjustment
= 1;
1053 $ns = $this->mTitle
->getNamespace();
1054 $ttl = $this->mTitle
->getDBkey();
1056 # If this is a comment, add the summary as headline
1057 if($comment && $summary!="") {
1058 $text="== {$summary} ==\n\n".$text;
1060 $text = $this->preSaveTransform( $text );
1061 $isminor = ( $isminor && $wgUser->isLoggedIn() ) ?
1 : 0;
1062 $now = wfTimestampNow();
1064 $dbw =& wfGetDB( DB_MASTER
);
1066 # Add the page record; stake our claim on this title!
1067 $newid = $this->insertOn( $dbw );
1069 # Save the revision text...
1070 $revision = new Revision( array(
1072 'comment' => $summary,
1073 'minor_edit' => $isminor,
1076 $revisionId = $revision->insertOn( $dbw );
1078 $this->mTitle
->resetArticleID( $newid );
1080 # Update the page record with revision data
1081 $this->updateRevisionOn( $dbw, $revision, 0 );
1083 Article
::onArticleCreate( $this->mTitle
);
1085 RecentChange
::notifyNew( $now, $this->mTitle
, $isminor, $wgUser, $summary, 'default',
1086 '', strlen( $text ), $revisionId );
1090 if(!$this->mTitle
->userIsWatching()) $this->watch();
1092 if ( $this->mTitle
->userIsWatching() ) {
1097 # The talk page isn't in the regular link tables, so we need to update manually:
1098 $talkns = $ns ^
1; # talk -> normal; normal -> talk
1099 $dbw->update( 'page',
1100 array( 'page_touched' => $dbw->timestamp($now) ),
1101 array( 'page_namespace' => $talkns,
1102 'page_title' => $ttl ),
1105 # standard deferred updates
1106 $this->editUpdates( $text, $summary, $isminor, $now );
1108 $oldid = 0; # new article
1109 $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
1111 wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text,
1113 $watchthis, NULL ) );
1114 wfProfileOut( $fname );
1117 function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '', $edittime = NULL) {
1118 $this->replaceSection( $section, $text, $summary, $edittime );
1121 function replaceSection($section, $text, $summary = '', $edittime = NULL) {
1122 $fname = 'Article::replaceSection';
1123 wfProfileIn( $fname );
1125 if ($section != '') {
1126 if( is_null( $edittime ) ) {
1127 $rev = Revision
::newFromTitle( $this->mTitle
);
1129 $dbw =& wfGetDB( DB_MASTER
);
1130 $rev = Revision
::loadFromTimestamp( $dbw, $this->mTitle
, $edittime );
1132 $oldtext = $rev->getText();
1134 if($section=='new') {
1135 if($summary) $subject="== {$summary} ==\n\n";
1136 $text=$oldtext."\n\n".$subject.$text;
1139 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
1140 # comments to be stripped as well)
1141 $striparray=array();
1142 $parser=new Parser();
1143 $parser->mOutputType
=OT_WIKI
;
1144 $parser->mOptions
= new ParserOptions();
1145 $oldtext=$parser->strip($oldtext, $striparray, true);
1147 # now that we can be sure that no pseudo-sections are in the source,
1149 # Unfortunately we can't simply do a preg_replace because that might
1150 # replace the wrong section, so we have to use the section counter instead
1151 $secs=preg_split('/(^=+.+?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)(?!\S)/mi',
1152 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE
);
1153 $secs[$section*2]=$text."\n\n"; // replace with edited
1155 # section 0 is top (intro) section
1158 # headline of old section - we need to go through this section
1159 # to determine if there are any subsections that now need to
1160 # be erased, as the mother section has been replaced with
1161 # the text of all subsections.
1162 $headline=$secs[$section*2-1];
1163 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$headline,$matches);
1164 $hlevel=$matches[1];
1166 # determine headline level for wikimarkup headings
1167 if(strpos($hlevel,'=')!==false) {
1168 $hlevel=strlen($hlevel);
1171 $secs[$section*2-1]=''; // erase old headline
1174 while(!empty($secs[$count*2-1]) && !$break) {
1176 $subheadline=$secs[$count*2-1];
1178 '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$subheadline,$matches);
1179 $subhlevel=$matches[1];
1180 if(strpos($subhlevel,'=')!==false) {
1181 $subhlevel=strlen($subhlevel);
1183 if($subhlevel > $hlevel) {
1184 // erase old subsections
1185 $secs[$count*2-1]='';
1188 if($subhlevel <= $hlevel) {
1196 $text=join('',$secs);
1197 # reinsert the stuff that we stripped out earlier
1198 $text=$parser->unstrip($text,$striparray);
1199 $text=$parser->unstripNoWiki($text,$striparray);
1203 wfProfileOut( $fname );
1208 * Change an existing article. Puts the previous version back into the old table, updates RC
1209 * and all necessary caches, mostly via the deferred update array.
1211 * It is possible to call this function from a command-line script, but note that you should
1212 * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
1214 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
1215 global $wgOut, $wgUser;
1216 global $wgDBtransactions, $wgMwRedir;
1217 global $wgUseSquid, $wgInternalServer, $wgPostCommitUpdateList, $wgUseFileCache;
1219 $fname = 'Article::updateArticle';
1220 wfProfileIn( $fname );
1223 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1225 &$watchthis, &$sectionanchor ) ) ) {
1226 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1227 wfProfileOut( $fname );
1231 $isminor = ( $minor && $wgUser->isLoggedIn() );
1232 if ( $this->isRedirect( $text ) ) {
1233 # Remove all content but redirect
1234 # This could be done by reconstructing the redirect from a title given by
1235 # Title::newFromRedirect(), but then we wouldn't know which synonym the user
1237 if ( preg_match( "/^((" . $wgMwRedir->getBaseRegex() . ')[^\\n]+)/i', $text, $m ) ) {
1239 $text = $m[1] . "\n";
1242 else { $redir = 0; }
1244 $text = $this->preSaveTransform( $text );
1245 $dbw =& wfGetDB( DB_MASTER
);
1246 $now = wfTimestampNow();
1248 # Update article, but only if changed.
1250 # It's important that we either rollback or complete, otherwise an attacker could
1251 # overwrite cur entries by sending precisely timed user aborts. Random bored users
1252 # could conceivably have the same effect, especially if cur is locked for long periods.
1253 if( !$wgDBtransactions ) {
1254 $userAbort = ignore_user_abort( true );
1257 $oldtext = $this->getContent( true );
1258 $oldsize = strlen( $oldtext );
1259 $newsize = strlen( $text );
1262 if ( 0 != strcmp( $text, $oldtext ) ) {
1263 $this->mGoodAdjustment
= $this->isCountable( $text )
1264 - $this->isCountable( $oldtext );
1265 $this->mTotalAdjustment
= 0;
1266 $now = wfTimestampNow();
1268 $lastRevision = $dbw->selectField(
1269 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1271 $revision = new Revision( array(
1272 'page' => $this->getId(),
1273 'comment' => $summary,
1274 'minor_edit' => $isminor,
1278 $dbw->immediateCommit();
1280 $revisionId = $revision->insertOn( $dbw );
1283 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1286 /* Belated edit conflict! Run away!! */
1290 # Update recentchanges and purge cache and whatnot
1291 $bot = (int)($wgUser->isBot() ||
$forceBot);
1292 RecentChange
::notifyEdit( $now, $this->mTitle
, $isminor, $wgUser, $summary,
1293 $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1295 Article
::onArticleEdit( $this->mTitle
);
1300 if( !$wgDBtransactions ) {
1301 ignore_user_abort( $userAbort );
1306 if (!$this->mTitle
->userIsWatching()) {
1307 $dbw->immediateCommit();
1313 if ( $this->mTitle
->userIsWatching() ) {
1314 $dbw->immediateCommit();
1320 # standard deferred updates
1321 $this->editUpdates( $text, $summary, $minor, $now );
1325 # Template namespace
1326 # Purge all articles linking here
1327 if ( $this->mTitle
->getNamespace() == NS_TEMPLATE
) {
1328 $titles = $this->mTitle
->getLinksTo();
1329 Title
::touchArray( $titles );
1330 if ( $wgUseSquid ) {
1331 foreach ( $titles as $title ) {
1332 $urls[] = $title->getInternalURL();
1338 if ( $wgUseSquid ) {
1339 $urls = array_merge( $urls, $this->mTitle
->getSquidURLs() );
1340 $u = new SquidUpdate( $urls );
1341 array_push( $wgPostCommitUpdateList, $u );
1345 if ( $wgUseFileCache ) {
1346 $cm = new CacheManager($this->mTitle
);
1347 @unlink
($cm->fileCacheName());
1350 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
1352 wfRunHooks( 'ArticleSaveComplete',
1353 array( &$this, &$wgUser, $text,
1355 $watchthis, $sectionanchor ) );
1356 wfProfileOut( $fname );
1361 * After we've either updated or inserted the article, update
1362 * the link tables and redirect to the new page.
1364 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
1365 global $wgUseDumbLinkUpdate, $wgAntiLockFlags, $wgOut, $wgUser, $wgLinkCache, $wgEnotif;
1366 global $wgUseEnotif;
1368 $fname = 'Article::showArticle';
1369 wfProfileIn( $fname );
1371 $wgLinkCache = new LinkCache();
1373 if ( !$wgUseDumbLinkUpdate ) {
1374 # Preload links to reduce lock time
1375 if ( $wgAntiLockFlags & ALF_PRELOAD_LINKS
) {
1376 $wgLinkCache->preFill( $this->mTitle
);
1377 $wgLinkCache->clear();
1381 # Parse the text and replace links with placeholders
1382 $wgOut = new OutputPage();
1384 # Pass the current title along in case we're creating a wiki page
1385 # which is different than the currently displayed one (e.g. image
1386 # pages created on file uploads); otherwise, link updates will
1388 $wgOut->addWikiTextWithTitle( $text, $this->mTitle
);
1390 if ( !$wgUseDumbLinkUpdate ) {
1391 # Move the current links back to the second register
1392 $wgLinkCache->swapRegisters();
1394 # Get old version of link table to allow incremental link updates
1395 # Lock this data now since it is needed for an update
1396 $wgLinkCache->forUpdate( true );
1397 $wgLinkCache->preFill( $this->mTitle
);
1399 # Swap this old version back into its rightful place
1400 $wgLinkCache->swapRegisters();
1403 if( $this->isRedirect( $text ) )
1407 $wgOut->redirect( $this->mTitle
->getFullURL( $r ).$sectionanchor );
1409 if ( $wgUseEnotif ) {
1410 # this would be better as an extension hook
1411 include_once( "UserMailer.php" );
1412 $wgEnotif = new EmailNotification ();
1413 $wgEnotif->notifyOnPageChange( $this->mTitle
, $now, $summary, $me2, $oldid );
1415 wfProfileOut( $fname );
1419 * Mark this particular edit as patrolled
1421 function markpatrolled() {
1422 global $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgUseRCPatrol, $wgUser;
1423 $wgOut->setRobotpolicy( 'noindex,follow' );
1425 if ( !$wgUseRCPatrol )
1427 $wgOut->errorpage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1430 if ( $wgUser->isAnon() )
1432 $wgOut->loginToUse();
1435 if ( $wgOnlySysopsCanPatrol && !$wgUser->isAllowed('patrol') )
1437 $wgOut->sysopRequired();
1440 $rcid = $wgRequest->getVal( 'rcid' );
1441 if ( !is_null ( $rcid ) )
1443 RecentChange
::markPatrolled( $rcid );
1444 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1445 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1447 $rcTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
1448 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
1452 $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1459 function validate() {
1460 global $wgOut, $wgUser, $wgRequest, $wgUseValidation;
1462 if ( !$wgUseValidation ) # Are we using article validation at all?
1464 $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
1468 $wgOut->setRobotpolicy( 'noindex,follow' );
1469 $revision = $wgRequest->getVal( 'revision' );
1471 include_once ( "SpecialValidate.php" ) ; # The "Validation" class
1473 $v = new Validation
;
1474 if ( $wgRequest->getVal ( "mode" , "" ) == "list" )
1475 $t = $v->showList ( $this ) ;
1476 else if ( $wgRequest->getVal ( "mode" , "" ) == "details" )
1477 $t = $v->showDetails ( $this , $wgRequest->getVal( 'revision' ) ) ;
1479 $t = $v->validatePageForm ( $this , $revision ) ;
1481 $wgOut->addHTML ( $t ) ;
1485 * Add this page to $wgUser's watchlist
1490 global $wgUser, $wgOut;
1492 if ( $wgUser->isAnon() ) {
1493 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1496 if ( wfReadOnly() ) {
1497 $wgOut->readOnlyPage();
1501 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1503 $wgUser->addWatch( $this->mTitle
);
1504 $wgUser->saveSettings();
1506 wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1508 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1509 $wgOut->setRobotpolicy( 'noindex,follow' );
1511 $link = $this->mTitle
->getPrefixedText();
1512 $text = wfMsg( 'addedwatchtext', $link );
1513 $wgOut->addWikiText( $text );
1516 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1520 * Stop watching a page
1523 function unwatch() {
1525 global $wgUser, $wgOut;
1527 if ( $wgUser->isAnon() ) {
1528 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1531 if ( wfReadOnly() ) {
1532 $wgOut->readOnlyPage();
1536 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1538 $wgUser->removeWatch( $this->mTitle
);
1539 $wgUser->saveSettings();
1541 wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1543 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1544 $wgOut->setRobotpolicy( 'noindex,follow' );
1546 $link = $this->mTitle
->getPrefixedText();
1547 $text = wfMsg( 'removedwatchtext', $link );
1548 $wgOut->addWikiText( $text );
1551 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1557 function protect( $limit = 'sysop' ) {
1558 global $wgUser, $wgOut, $wgRequest;
1560 if ( ! $wgUser->isAllowed('protect') ) {
1561 $wgOut->sysopRequired();
1564 if ( wfReadOnly() ) {
1565 $wgOut->readOnlyPage();
1568 $id = $this->mTitle
->getArticleID();
1570 $wgOut->fatalError( wfMsg( 'badarticleerror' ) );
1574 $confirm = $wgRequest->wasPosted() &&
1575 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1576 $moveonly = $wgRequest->getBool( 'wpMoveOnly' );
1577 $reason = $wgRequest->getText( 'wpReasonProtect' );
1580 $dbw =& wfGetDB( DB_MASTER
);
1581 $dbw->update( 'page',
1583 'page_touched' => $dbw->timestamp(),
1584 'page_restrictions' => (string)$limit
1585 ), array( /* WHERE */
1587 ), 'Article::protect'
1590 $restrictions = "move=" . $limit;
1592 $restrictions .= ":edit=" . $limit;
1594 if (wfRunHooks('ArticleProtect', array(&$this, &$wgUser, $limit == 'sysop', $reason, $moveonly))) {
1596 $dbw =& wfGetDB( DB_MASTER
);
1597 $dbw->update( 'page',
1599 'page_touched' => $dbw->timestamp(),
1600 'page_restrictions' => $restrictions
1601 ), array( /* WHERE */
1603 ), 'Article::protect'
1606 wfRunHooks('ArticleProtectComplete', array(&$this, &$wgUser, $limit == 'sysop', $reason, $moveonly));
1608 $log = new LogPage( 'protect' );
1609 if ( $limit === '' ) {
1610 $log->addEntry( 'unprotect', $this->mTitle
, $reason );
1612 $log->addEntry( 'protect', $this->mTitle
, $reason );
1614 $wgOut->redirect( $this->mTitle
->getFullURL() );
1618 return $this->confirmProtect( '', '', $limit );
1623 * Output protection confirmation dialog
1625 function confirmProtect( $par, $reason, $limit = 'sysop' ) {
1626 global $wgOut, $wgUser;
1628 wfDebug( "Article::confirmProtect\n" );
1630 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1631 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1637 if ( $limit === '' ) {
1638 $wgOut->setPageTitle( wfMsg( 'confirmunprotect' ) );
1639 $wgOut->setSubtitle( wfMsg( 'unprotectsub', $sub ) );
1640 $wgOut->addWikiText( wfMsg( 'confirmunprotecttext' ) );
1641 $protcom = htmlspecialchars( wfMsg( 'unprotectcomment' ) );
1642 $formaction = $this->mTitle
->escapeLocalURL( 'action=unprotect' . $par );
1644 $wgOut->setPageTitle( wfMsg( 'confirmprotect' ) );
1645 $wgOut->setSubtitle( wfMsg( 'protectsub', $sub ) );
1646 $wgOut->addWikiText( wfMsg( 'confirmprotecttext' ) );
1647 $moveonly = htmlspecialchars( wfMsg( 'protectmoveonly' ) );
1648 $protcom = htmlspecialchars( wfMsg( 'protectcomment' ) );
1649 $formaction = $this->mTitle
->escapeLocalURL( 'action=protect' . $par );
1652 $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
1653 $token = htmlspecialchars( $wgUser->editToken() );
1656 <form id='protectconfirm' method='post' action=\"{$formaction}\">
1660 <label for='wpReasonProtect'>{$protcom}:</label>
1663 <input type='text' size='60' name='wpReasonProtect' id='wpReasonProtect' value=\"" . htmlspecialchars( $reason ) . "\" />
1666 if($moveonly != '') {
1670 <input type='checkbox' name='wpMoveOnly' value='1' id='wpMoveOnly' />
1673 <label for='wpMoveOnly'>{$moveonly}</label>
1681 <input type='submit' name='wpConfirmProtectB' value=\"{$confirm}\" />
1685 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1688 $wgOut->returnToMain( false );
1692 * Unprotect the pages
1694 function unprotect() {
1695 return $this->protect( '' );
1699 * UI entry point for page deletion
1702 global $wgUser, $wgOut, $wgMessageCache, $wgRequest;
1703 $fname = 'Article::delete';
1704 $confirm = $wgRequest->wasPosted() &&
1705 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1706 $reason = $wgRequest->getText( 'wpReason' );
1708 # This code desperately needs to be totally rewritten
1711 if( ( !$wgUser->isAllowed( 'delete' ) ) ) {
1712 $wgOut->sysopRequired();
1715 if( wfReadOnly() ) {
1716 $wgOut->readOnlyPage();
1720 # Better double-check that it hasn't been deleted yet!
1721 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1722 if( !$this->mTitle
->exists() ) {
1723 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1728 $this->doDelete( $reason );
1732 # determine whether this page has earlier revisions
1733 # and insert a warning if it does
1734 # we select the text because it might be useful below
1735 $dbr =& $this->getDB();
1736 $ns = $this->mTitle
->getNamespace();
1737 $title = $this->mTitle
->getDBkey();
1738 $revisions = $dbr->select( array( 'page', 'revision' ),
1739 array( 'rev_id', 'rev_user_text' ),
1741 'page_namespace' => $ns,
1742 'page_title' => $title,
1743 'rev_page = page_id'
1744 ), $fname, $this->getSelectOptions( array( 'ORDER BY' => 'rev_timestamp DESC' ) )
1747 if( $dbr->numRows( $revisions ) > 1 && !$confirm ) {
1748 $skin=$wgUser->getSkin();
1749 $wgOut->addHTML('<b>'.wfMsg('historywarning'));
1750 $wgOut->addHTML( $skin->historyLink() .'</b>');
1754 $rev = Revision
::newFromTitle( $this->mTitle
);
1756 # Fetch name(s) of contributors
1758 $all_same_user = true;
1759 while( $row = $dbr->fetchObject( $revisions ) ) {
1760 if( $rev_name != '' && $rev_name != $row->rev_user_text
) {
1761 $all_same_user = false;
1763 $rev_name = $row->rev_user_text
;
1767 if( !is_null( $rev ) ) {
1768 # if this is a mini-text, we can paste part of it into the deletion reason
1769 $text = $rev->getText();
1771 #if this is empty, an earlier revision may contain "useful" text
1774 $prev = $rev->getPrevious();
1776 $text = $prev->getText();
1781 $length = strlen( $text );
1783 # this should not happen, since it is not possible to store an empty, new
1784 # page. Let's insert a standard text in case it does, though
1785 if( $length == 0 && $reason === '' ) {
1786 $reason = wfMsgForContent( 'exblank' );
1789 if( $length < 500 && $reason === '' ) {
1790 # comment field=255, let's grep the first 150 to have some user
1793 $text = $wgContLang->truncate( $text, 150, '...' );
1795 # let's strip out newlines
1796 $text = preg_replace( "/[\n\r]/", '', $text );
1799 if( !$all_same_user ) {
1800 $reason = wfMsgForContent( 'excontent', $text );
1802 $reason = wfMsgForContent( 'excontentauthor', $text, $rev_name );
1805 $reason = wfMsgForContent( 'exbeforeblank', $text );
1810 return $this->confirmDelete( '', $reason );
1814 * Output deletion confirmation dialog
1816 function confirmDelete( $par, $reason ) {
1817 global $wgOut, $wgUser;
1819 wfDebug( "Article::confirmDelete\n" );
1821 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1822 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1823 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1824 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1826 $formaction = $this->mTitle
->escapeLocalURL( 'action=delete' . $par );
1828 $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
1829 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1830 $token = htmlspecialchars( $wgUser->editToken() );
1833 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1837 <label for='wpReason'>{$delcom}:</label>
1840 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1846 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1850 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1853 $wgOut->returnToMain( false );
1858 * Perform a deletion and output success or failure messages
1860 function doDelete( $reason ) {
1861 global $wgOut, $wgUser, $wgContLang;
1862 $fname = 'Article::doDelete';
1863 wfDebug( $fname."\n" );
1865 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
1866 if ( $this->doDeleteArticle( $reason ) ) {
1867 $deleted = $this->mTitle
->getPrefixedText();
1869 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1870 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1872 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
1873 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1875 $wgOut->addWikiText( $text );
1876 $wgOut->returnToMain( false );
1877 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
1879 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1885 * Back-end article deletion
1886 * Deletes the article with database consistency, writes logs, purges caches
1889 function doDeleteArticle( $reason ) {
1891 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer, $wgPostCommitUpdateList;
1892 global $wgUseTrackbacks;
1894 $fname = 'Article::doDeleteArticle';
1895 wfDebug( $fname."\n" );
1897 $dbw =& wfGetDB( DB_MASTER
);
1898 $ns = $this->mTitle
->getNamespace();
1899 $t = $this->mTitle
->getDBkey();
1900 $id = $this->mTitle
->getArticleID();
1902 if ( $t == '' ||
$id == 0 ) {
1906 $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ), -1 );
1907 array_push( $wgDeferredUpdateList, $u );
1909 $linksTo = $this->mTitle
->getLinksTo();
1912 if ( $wgUseSquid ) {
1914 $this->mTitle
->getInternalURL(),
1915 $this->mTitle
->getInternalURL( 'history' )
1918 $u = SquidUpdate
::newFromTitles( $linksTo, $urls );
1919 array_push( $wgPostCommitUpdateList, $u );
1923 # Client and file cache invalidation
1924 Title
::touchArray( $linksTo );
1927 // For now, shunt the revision data into the archive table.
1928 // Text is *not* removed from the text table; bulk storage
1929 // is left intact to avoid breaking block-compression or
1930 // immutable storage schemes.
1932 // For backwards compatibility, note that some older archive
1933 // table entries will have ar_text and ar_flags fields still.
1935 // In the future, we may keep revisions and mark them with
1936 // the rev_deleted field, which is reserved for this purpose.
1937 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
1939 'ar_namespace' => 'page_namespace',
1940 'ar_title' => 'page_title',
1941 'ar_comment' => 'rev_comment',
1942 'ar_user' => 'rev_user',
1943 'ar_user_text' => 'rev_user_text',
1944 'ar_timestamp' => 'rev_timestamp',
1945 'ar_minor_edit' => 'rev_minor_edit',
1946 'ar_rev_id' => 'rev_id',
1947 'ar_text_id' => 'rev_text_id',
1950 'page_id = rev_page'
1954 # Now that it's safely backed up, delete it
1955 $dbw->delete( 'revision', array( 'rev_page' => $id ), $fname );
1956 $dbw->delete( 'page', array( 'page_id' => $id ), $fname);
1958 if ($wgUseTrackbacks)
1959 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), $fname );
1961 # Clean up recentchanges entries...
1962 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
1964 # Finally, clean up the link tables
1965 $t = $this->mTitle
->getPrefixedDBkey();
1967 Article
::onArticleDelete( $this->mTitle
);
1969 # Delete outgoing links
1970 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
1971 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
1972 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
1975 $log = new LogPage( 'delete' );
1976 $log->addEntry( 'delete', $this->mTitle
, $reason );
1978 # Clear the cached article id so the interface doesn't act like we exist
1979 $this->mTitle
->resetArticleID( 0 );
1980 $this->mTitle
->mArticleID
= 0;
1985 * Revert a modification
1987 function rollback() {
1988 global $wgUser, $wgOut, $wgRequest;
1989 $fname = 'Article::rollback';
1991 if ( ! $wgUser->isAllowed('rollback') ) {
1992 $wgOut->sysopRequired();
1995 if ( wfReadOnly() ) {
1996 $wgOut->readOnlyPage( $this->getContent( true ) );
1999 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
2000 array( $this->mTitle
->getPrefixedText(),
2001 $wgRequest->getVal( 'from' ) ) ) ) {
2002 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
2003 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
2006 $dbw =& wfGetDB( DB_MASTER
);
2008 # Enhanced rollback, marks edits rc_bot=1
2009 $bot = $wgRequest->getBool( 'bot' );
2011 # Replace all this user's current edits with the next one down
2012 $tt = $this->mTitle
->getDBKey();
2013 $n = $this->mTitle
->getNamespace();
2015 # Get the last editor, lock table exclusively
2017 $current = Revision
::newFromTitle( $this->mTitle
);
2018 if( is_null( $current ) ) {
2019 # Something wrong... no page?
2021 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
2025 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
2026 if( $from != $current->getUserText() ) {
2027 $wgOut->setPageTitle( wfMsg('rollbackfailed') );
2028 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
2029 htmlspecialchars( $this->mTitle
->getPrefixedText()),
2030 htmlspecialchars( $from ),
2031 htmlspecialchars( $current->getUserText() ) ) );
2032 if( $current->getComment() != '') {
2034 wfMsg( 'editcomment',
2035 htmlspecialchars( $current->getComment() ) ) );
2040 # Get the last edit not by this guy
2041 $user = intval( $current->getUser() );
2042 $user_text = $dbw->addQuotes( $current->getUserText() );
2043 $s = $dbw->selectRow( 'revision',
2044 array( 'rev_id', 'rev_timestamp' ),
2046 'rev_page' => $current->getPage(),
2047 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
2050 'USE INDEX' => 'page_timestamp',
2051 'ORDER BY' => 'rev_timestamp DESC' )
2053 if( $s === false ) {
2056 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2057 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
2062 # Mark all reverted edits as bot
2063 $dbw->update( 'recentchanges',
2066 ), array( /* WHERE */
2067 'rc_cur_id' => $current->getPage(),
2068 'rc_user_text' => $current->getUserText(),
2069 "rc_timestamp > '{$s->rev_timestamp}'",
2075 $target = Revision
::newFromId( $s->rev_id
);
2076 $newcomment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
2078 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2079 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2080 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newcomment ) . "</h2>\n<hr />\n" );
2082 $this->updateArticle( $target->getText(), $newcomment, 1, $this->mTitle
->userIsWatching(), $bot );
2083 Article
::onArticleEdit( $this->mTitle
);
2086 $wgOut->returnToMain( false );
2091 * Do standard deferred updates after page view
2094 function viewUpdates() {
2095 global $wgDeferredUpdateList, $wgUseEnotif;
2097 if ( 0 != $this->getID() ) {
2098 global $wgDisableCounters;
2099 if( !$wgDisableCounters ) {
2100 Article
::incViewCount( $this->getID() );
2101 $u = new SiteStatsUpdate( 1, 0, 0 );
2102 array_push( $wgDeferredUpdateList, $u );
2106 # Update newtalk status if user is reading their own
2110 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&&
2111 $this->mTitle
->getText() == $wgUser->getName())
2113 if ( $wgUseEnotif ) {
2114 require_once( 'UserTalkUpdate.php' );
2115 $u = new UserTalkUpdate( 0, $this->mTitle
->getNamespace(), $this->mTitle
->getDBkey(), false, false, false );
2117 $wgUser->setNewtalk(0);
2118 $wgUser->saveNewtalk();
2120 } elseif ( $wgUseEnotif ) {
2121 $wgUser->clearNotification( $this->mTitle
);
2127 * Do standard deferred updates after page edit.
2128 * Every 1000th edit, prune the recent changes table.
2130 * @param string $text
2132 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange) {
2133 global $wgDeferredUpdateList, $wgDBname, $wgMemc;
2134 global $wgMessageCache, $wgUser, $wgUseEnotif;
2137 if ( 0 == mt_rand( 0, 999 ) ) {
2138 # Periodically flush old entries from the recentchanges table.
2140 $dbw =& wfGetDB( DB_MASTER
);
2141 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2142 $recentchanges = $dbw->tableName( 'recentchanges' );
2143 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2144 //$dbw->query( $sql ); // HACK: disabled for now, slowness
2146 // re-enabled for commit of unrelated live changes -- TS
2147 $dbw->query( $sql );
2150 $id = $this->getID();
2151 $title = $this->mTitle
->getPrefixedDBkey();
2152 $shortTitle = $this->mTitle
->getDBkey();
2155 $u = new LinksUpdate( $id, $title );
2156 array_push( $wgDeferredUpdateList, $u );
2157 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment
, $this->mTotalAdjustment
);
2158 array_push( $wgDeferredUpdateList, $u );
2159 $u = new SearchUpdate( $id, $title, $text );
2160 array_push( $wgDeferredUpdateList, $u );
2162 # If this is another user's talk page, update newtalk
2164 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&& $shortTitle != $wgUser->getName()) {
2165 if ( $wgUseEnotif ) {
2166 require_once( 'UserTalkUpdate.php' );
2167 $u = new UserTalkUpdate( 1, $this->mTitle
->getNamespace(), $shortTitle, $summary,
2168 $minoredit, $timestamp_of_pagechange);
2170 $other = User
::newFromName( $shortTitle );
2171 if( is_null( $other ) && User
::isIP( $shortTitle ) ) {
2172 // An anonymous user
2173 $other = new User();
2174 $other->setName( $shortTitle );
2177 $other->setNewtalk(1);
2178 $other->saveNewtalk();
2183 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2184 $wgMessageCache->replace( $shortTitle, $text );
2190 * @todo document this function
2192 * @param string $oldid Revision ID of this article revision
2194 function setOldSubtitle( $oldid=0 ) {
2195 global $wgLang, $wgOut, $wgUser;
2197 $current = ( $oldid == $this->mLatest
);
2198 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
2199 $sk = $wgUser->getSkin();
2201 ?
wfMsg( 'currentrevisionlink' )
2202 : $lnk = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'currentrevisionlink' ) );
2203 $prevlink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid );
2204 $nextlink = $current
2205 ?
wfMsg( 'nextrevision' )
2206 : $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2207 $r = wfMsg( 'revisionasofwithlink', $td, $lnk, $prevlink, $nextlink );
2208 $wgOut->setSubtitle( $r );
2212 * This function is called right before saving the wikitext,
2213 * so we can do things like signatures and links-in-context.
2215 * @param string $text
2217 function preSaveTransform( $text ) {
2218 global $wgParser, $wgUser;
2219 return $wgParser->preSaveTransform( $text, $this->mTitle
, $wgUser, ParserOptions
::newFromUser( $wgUser ) );
2222 /* Caching functions */
2225 * checkLastModified returns true if it has taken care of all
2226 * output to the client that is necessary for this request.
2227 * (that is, it has sent a cached version of the page)
2229 function tryFileCache() {
2230 static $called = false;
2232 wfDebug( " tryFileCache() -- called twice!?\n" );
2236 if($this->isFileCacheable()) {
2237 $touched = $this->mTouched
;
2238 $cache = new CacheManager( $this->mTitle
);
2239 if($cache->isFileCacheGood( $touched )) {
2241 wfDebug( " tryFileCache() - about to load\n" );
2242 $cache->loadFromFileCache();
2245 wfDebug( " tryFileCache() - starting buffer\n" );
2246 ob_start( array(&$cache, 'saveToFileCache' ) );
2249 wfDebug( " tryFileCache() - not cacheable\n" );
2254 * Check if the page can be cached
2257 function isFileCacheable() {
2258 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
2259 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
2261 return $wgUseFileCache
2262 and (!$wgShowIPinHeader)
2263 and ($this->getID() != 0)
2264 and ($wgUser->isAnon())
2265 and (!$wgUser->getNewtalk())
2266 and ($this->mTitle
->getNamespace() != NS_SPECIAL
)
2267 and (empty( $action ) ||
$action == 'view')
2268 and (!isset($oldid))
2270 and (!isset($redirect))
2271 and (!isset($printable))
2272 and (!$this->mRedirectedFrom
);
2276 * Loads cur_touched and returns a value indicating if it should be used
2279 function checkTouched() {
2280 $fname = 'Article::checkTouched';
2281 if( !$this->mDataLoaded
) {
2282 $dbr =& $this->getDB();
2283 $data = $this->pageDataFromId( $dbr, $this->getId() );
2285 $this->loadPageData( $data );
2288 return !$this->mIsRedirect
;
2292 * Edit an article without doing all that other stuff
2293 * The article must already exist; link tables etc
2294 * are not updated, caches are not flushed.
2296 * @param string $text text submitted
2297 * @param string $comment comment submitted
2298 * @param bool $minor whereas it's a minor modification
2300 function quickEdit( $text, $comment = '', $minor = 0 ) {
2301 $fname = 'Article::quickEdit';
2302 wfProfileIn( $fname );
2304 $dbw =& wfGetDB( DB_MASTER
);
2306 $revision = new Revision( array(
2307 'page' => $this->getId(),
2309 'comment' => $comment,
2310 'minor_edit' => $minor ?
1 : 0,
2312 $revisionId = $revision->insertOn( $dbw );
2313 $this->updateRevisionOn( $dbw, $revision );
2316 wfProfileOut( $fname );
2320 * Used to increment the view counter
2323 * @param integer $id article id
2325 function incViewCount( $id ) {
2326 $id = intval( $id );
2327 global $wgHitcounterUpdateFreq;
2329 $dbw =& wfGetDB( DB_MASTER
);
2330 $pageTable = $dbw->tableName( 'page' );
2331 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2332 $acchitsTable = $dbw->tableName( 'acchits' );
2334 if( $wgHitcounterUpdateFreq <= 1 ){ //
2335 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2339 # Not important enough to warrant an error page in case of failure
2340 $oldignore = $dbw->ignoreErrors( true );
2342 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2344 $checkfreq = intval( $wgHitcounterUpdateFreq/25 +
1 );
2345 if( (rand() %
$checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2346 # Most of the time (or on SQL errors), skip row count check
2347 $dbw->ignoreErrors( $oldignore );
2351 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2352 $row = $dbw->fetchObject( $res );
2353 $rown = intval( $row->n
);
2354 if( $rown >= $wgHitcounterUpdateFreq ){
2355 wfProfileIn( 'Article::incViewCount-collect' );
2356 $old_user_abort = ignore_user_abort( true );
2358 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2359 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
2360 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2362 $dbw->query("DELETE FROM $hitcounterTable");
2363 $dbw->query('UNLOCK TABLES');
2364 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
2365 'WHERE page_id = hc_id');
2366 $dbw->query("DROP TABLE $acchitsTable");
2368 ignore_user_abort( $old_user_abort );
2369 wfProfileOut( 'Article::incViewCount-collect' );
2371 $dbw->ignoreErrors( $oldignore );
2375 * The onArticle*() functions are supposed to be a kind of hooks
2376 * which should be called whenever any of the specified actions
2379 * This is a good place to put code to clear caches, for instance.
2381 * This is called on page move and undelete, as well as edit
2383 * @param $title_obj a title object
2386 function onArticleCreate($title_obj) {
2387 global $wgUseSquid, $wgPostCommitUpdateList;
2389 $title_obj->touchLinks();
2390 $titles = $title_obj->getLinksTo();
2393 if ( $wgUseSquid ) {
2394 $urls = $title_obj->getSquidURLs();
2395 foreach ( $titles as $linkTitle ) {
2396 $urls[] = $linkTitle->getInternalURL();
2398 $u = new SquidUpdate( $urls );
2399 array_push( $wgPostCommitUpdateList, $u );
2403 function onArticleDelete( $title ) {
2404 global $wgMessageCache;
2406 $title->touchLinks();
2408 if( $title->getNamespace() == NS_MEDIAWIKI
) {
2409 $wgMessageCache->replace( $title->getDBkey(), false );
2413 function onArticleEdit($title_obj) {
2414 // This would be an appropriate place to purge caches.
2415 // Why's this not in here now?
2421 * Info about this page
2422 * Called for ?action=info when $wgAllowPageInfo is on.
2427 global $wgLang, $wgOut, $wgAllowPageInfo, $wgUser;
2428 $fname = 'Article::info';
2430 if ( !$wgAllowPageInfo ) {
2431 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
2435 $page = $this->mTitle
->getSubjectPage();
2437 $wgOut->setPagetitle( $page->getPrefixedText() );
2438 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
2440 # first, see if the page exists at all.
2441 $exists = $page->getArticleId() != 0;
2443 $wgOut->addHTML( wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' ) );
2445 $dbr =& $this->getDB( DB_SLAVE
);
2447 'wl_title' => $page->getDBkey(),
2448 'wl_namespace' => $page->getNamespace() );
2449 $numwatchers = $dbr->selectField(
2454 $this->getSelectOptions() );
2456 $pageInfo = $this->pageCountInfo( $page );
2457 $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
2459 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
2460 $wgOut->addHTML( "<li>" . wfMsg('numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>');
2462 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>');
2464 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
2466 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
2468 $wgOut->addHTML( '</ul>' );
2474 * Return the total number of edits and number of unique editors
2475 * on a given page. If page does not exist, returns false.
2477 * @param Title $title
2481 function pageCountInfo( $title ) {
2482 $id = $title->getArticleId();
2487 $dbr =& $this->getDB( DB_SLAVE
);
2489 $rev_clause = array( 'rev_page' => $id );
2490 $fname = 'Article::pageCountInfo';
2492 $edits = $dbr->selectField(
2497 $this->getSelectOptions() );
2499 $authors = $dbr->selectField(
2501 'COUNT(DISTINCT rev_user_text)',
2504 $this->getSelectOptions() );
2506 return array( 'edits' => $edits, 'authors' => $authors );
2510 * Return a list of templates used by this article.
2511 * Uses the links table to find the templates
2515 function getUsedTemplates() {
2517 $id = $this->mTitle
->getArticleID();
2519 $db =& wfGetDB( DB_SLAVE
);
2520 $res = $db->select( array( 'pagelinks' ),
2521 array( 'pl_title' ),
2524 'pl_namespace' => NS_TEMPLATE
),
2525 'Article:getUsedTemplates' );
2526 if ( false !== $res ) {
2527 if ( $db->numRows( $res ) ) {
2528 while ( $row = $db->fetchObject( $res ) ) {
2529 $result[] = $row->pl_title
;
2533 $db->freeResult( $res );